package com.dcm.order.controller;

import com.dcm.common.annotation.EnableResponseBodyAdvice;
import com.dcm.order.dto.AddressDto;
import com.dcm.order.dto.DistrictDto;
import com.dcm.order.entity.OrderEntity;
import com.dcm.order.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * [一句话描述该类的功能]
 *
 * @author : [pengrongsheng]
 * @createTime : [2021/3/30]
 */
@Api("OrderController")
@RestController
@RequestMapping("/order")
@EnableResponseBodyAdvice
public class OrderController {
    @Autowired
    private OrderService orderService;

    @ApiOperation("填写地址")
    @RequestMapping(value = "/insertOrderAddress", method = RequestMethod.POST)
    public void insertOrderAddress(@RequestBody AddressDto address) {
        orderService.insertOrderAddress(address);
    }

    @ApiOperation("添加订单")
    @RequestMapping(value = "/insertOrder", method = RequestMethod.POST)
    public void insertOrder(@RequestBody OrderEntity order) {
        orderService.insertOrder(order);
    }

    @ApiOperation("订单列表")
    @GetMapping(value = "/findAll")
    public List<OrderEntity> findAll() {
        return orderService.findAll();
    }

    @ApiOperation("根据id查询订单")
    @GetMapping("/findOneById")
    public OrderEntity findOneById(@RequestParam(value = "id", required = false) Long id) {
        return orderService.findOneById(id);
    }

    @ApiOperation("根据id查找省市区")
    @GetMapping("findCityById")
    public DistrictDto findCityById(@RequestParam(value = "id", required = false) Long id) {
        return orderService.findCityById(id);
    }

    @ApiOperation("城市选择：选择省市区")
    @GetMapping("findCityByPid")
    public List<DistrictDto> findCityByPid(@RequestParam(value = "pid", required = false) Long pid) {
        return orderService.findCityByPid(pid);
    }



}
